package com.example.dou2204;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.blankj.utilcode.util.ToastUtils;
import com.tencent.rtmp.TXLivePushConfig;
import com.tencent.rtmp.TXLivePusher;
import com.tencent.rtmp.ui.TXCloudVideoView;

public class ZhiboActivity extends AppCompatActivity {

    private Button start,end,getAddr;
    public LocationClient mLocationClient = null;
    private BDAbstractLocationListener myListener = new BDAbstractLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if(location==null){
                ToastUtils.showLong("定位不成功，未获取到地址");
            }else{
                ToastUtils.showLong("111====="+location.getLocationID()+"$$$$$$$==="+location.getAddrStr());//吐司详细地址
            }

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhibo);

        TXLivePushConfig mLivePushConfig  = new TXLivePushConfig();
        TXLivePusher mLivePusher = new TXLivePusher(this);


// 一般情况下不需要修改 config 的默认配置
        mLivePusher.setConfig(mLivePushConfig);

        //启动本地摄像头预览
        TXCloudVideoView mPusherView = (TXCloudVideoView) findViewById(R.id.pusher_tx_cloud_view);
        mLivePusher.startCameraPreview(mPusherView);
        start = findViewById(R.id.start);
        end = findViewById(R.id.end);
        getAddr = findViewById(R.id.getAddr);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String rtmpURL = "rtmp://200613.push.tlivecloud.com/live/txy?txSecret=b44233af9968f11d5581604e434dd7c0&txTime=668CDC3A"; //此处填写您的 rtmp 推流地址
                int ret = mLivePusher.startPusher(rtmpURL.trim());
                if (ret == -5) {
                    Log.i("sss", "startRTMPPush: license 校验失败");
                }

            }
        });
        end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLivePusher.stopPusher();
                mLivePusher.stopCameraPreview(true); //如果已经启动了摄像头预览，请在结束推流时将其关闭。
            }
        });
        getAddr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLocationClient = new LocationClient(getApplicationContext());
                //声明LocationClient类
                mLocationClient.registerLocationListener(myListener);

                LocationClientOption option = new LocationClientOption();

                option.setIsNeedAddress(true);
//可选，是否需要地址信息，默认为不需要，即参数为false
//如果开发者需要获得当前点的地址信息，此处必须为true

                option.setNeedNewVersionRgc(true);
//可选，设置是否需要最新版本的地址信息。默认需要，即参数为true

                mLocationClient.setLocOption(option);
                mLocationClient.start();
            }
        });
    }
}